//
//  FPRepayPlanModel.m
//  FinanceProject
//
//  Created by 陈显摆 on 2025/1/23.
//

#import "FPRepayPlanModel.h"

@implementation FPRepayPlanModel






+ (void)getListWithAmount:(NSString *)amount instalments:(NSString *)instalments interestRate:(NSString *)interestRate sucess:(void (^)(NSInteger code , NSString *message , NSArray *list))success failure:(void (^)(NSError *error))failure {
    
    NSMutableDictionary *param = APIClient.creatAPIDictionary;
    
    [param setObject:amount forKey:@"amount"];
    [param setObject:instalments forKey:@"instalments"];
    [param setObject:interestRate forKey:@"interestRate"];
    
    [[APIClient sharedInstance] requestWithURLString:[MAIN_URL stringByAppendingString:CACUL_URL] parameters:param type:HttpRequestTypePost success:^(id responseObject, NSString *msg, NSInteger code) {
        
        NSError *error;
        
        id object = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
        
        NSArray *list = [FPRepayPlanModel arrayOfModelsFromDictionaries:[object objectForKey:@"data"] error:&error];
        
        NSInteger httpCode = [[object objectForKey:@"code"] integerValue];
        
        NSString *message = [object objectForKey:@"msg"];
        
        if (success) {
            
            success(httpCode , message , list);
        }
        
    } failure:^(NSError *error) {
        
        if (failure) {
            failure(error);
        }
    }];
}


+ (void)applyLoanWithParam:(NSDictionary *)param success:(void (^)(NSInteger, NSString * _Nonnull , BOOL ))success failure:(void (^)(NSError * _Nonnull))failure {
    
    [[APIClient sharedInstance] requestWithURLString:[MAIN_URL stringByAppendingString:APPLY_LOAN_URL] parameters:param type:HttpRequestTypePost success:^(id responseObject, NSString *msg, NSInteger code) {
        
        NSError *error;
        
        id object = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
        
        NSInteger httpCode = [[object objectForKey:@"code"] integerValue];
        
        NSString *message = [object objectForKey:@"msg"];
        
        BOOL ret = NO;
        
        if ([object isKindOfClass:NSDictionary.class]) {
            
            id obj = [object objectForKey:@"data"];
            
            if ([obj isKindOfClass:NSDictionary.class]) {
                
                ret = [[obj objectForKey:@"succeed"] boolValue];
            }
        }
        
        if (success) {
            
            success(httpCode , message , ret);
        }
        
    } failure:^(NSError *error) {
        
        if (failure) {
            failure(error);
        }
    }];
}


@end
